<?php

namespace App\Logics;


use App\Models\User;
use App\Service\Base\Logic;

class UserLogic extends Logic
{

    // 登录
    public function onLogin()
    {
        $option   = $this->option();
        $username = $option->getData('username', null, 'trim');
        $password = $option->getData('password', null, 'trim');
        if(empty($username)){
            return $this->_returnFail('请输入用户名！！');
        }
        if(empty($password)){
            return $this->_returnFail('请输入密码！！');
        }

        //$option->throwIf(empty($username), '请输入用户名！！');
        //$option->throwIf(empty($password), '请输入密码！！');


        // 获取登录的用户信息
        $userDb = new User();
        $info   = $userDb->login($username, $password, 'username');
        if($info === false){
            return $this->_returnFail($userDb->getError());
        }

        return $info;
    }

}


